import { defineStore } from "pinia";
import { onMounted, ref } from "vue";
import axios from "axios";
const mapStore = defineStore('map-store', () => {
    const isEvent = ref(false)

    // 添加事件
    const isAdd = ref(false)
    const event_name = ref()
    const event_area = ref()
    const event_car_num = ref()
    const event_type = ref()
    const addLists = ref([])
    const total = ref()
    const curData = ref([])


    const otherEvent = ref()
    const dateYMD = ref()
    const dateTime = ref()

    // 添加点
    const position = ref()
    const attr = ref()
    const service = ref()

    // 事件查询
    const isSearch = ref(false)

    // 发布公告
    const isNotice = ref(false)
    const NoticeList = ref([{ time: '2024-7-30', text: '尊敬的用户,该页面不定时进行公告发布,请各位用户及时查阅公告!' }])
    const isLook = ref(false)

    // 可视化
    const event = ref([])

    onMounted(async () => {
        const res = await axios.get('http://39.103.151.139:8000/gis/event')
        res.data.features.forEach(item => {
            addLists.value.push({
                center: item.geometry.coordinates,
                driver: item.properties.driver,
                area: item.properties.area,
                car_num: item.properties.car_num,
                name: item.properties.name,
            })
        })
        total.value = addLists.value.length
        curData.value = addLists.value.slice(0, 4)
    })

    return {
        isEvent,
        isAdd,
        otherEvent,
        dateYMD,
        dateTime,
        position,
        attr,
        service,
        event_name,
        event_area,
        event_car_num,
        event_type,
        addLists,
        isSearch,
        isNotice,
        NoticeList,
        isLook,
        total,
        curData,
        event,
    }
})

export { mapStore }